package com.wnhz.work.yz.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.ArrangeProgressBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by d on 2016/12/19.
 * 住宿安排
 */

public class AccommodationActivity extends BaseActivity implements View.OnClickListener {

    private View hotel_name_lay;//宾馆
    private TextView hotel_name_tools;
    private EditText hotel_name_context_ed;
    private View room_lay;//房间
    private TextView room_name_tools;//房间
    private EditText room_context_ed;//房间
    private TextView select_tools;//时间提示
    private TextView select_tv;//时间选择

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dinner_arrangement);
        initData();
        initTitle();
        initView();
    }

    private ArrangeProgressBean.HostelInfoEntity hostel_info = new ArrangeProgressBean.HostelInfoEntity();

    private void initData() {
        hostel_info = ArrangeRouteActivity.maxBean.getHostel_info();
    }

    private TextView address_click;

    private void initView() {
        //  findViewById(R.id.select_lay).setOnClickListener(this);
        address_click = (TextView) findViewById(R.id.address_click);
        hotel_name_lay = findViewById(R.id.grogshop_name_lay);
        hotel_name_tools = (TextView) hotel_name_lay.findViewById(R.id.tools);
        hotel_name_tools.setText(R.string.accommodation_hotel_name_tools);
        hotel_name_context_ed = (EditText) hotel_name_lay.findViewById(R.id.context_ed);
        hotel_name_context_ed.setHint(R.string.accommodation_hotel_name_context_ed);

        room_lay = findViewById(R.id.box_lay);
        room_name_tools = (TextView) room_lay.findViewById(R.id.tools);
        room_name_tools.setText(R.string.accommodation_room_name_tools);
        room_context_ed = (EditText) room_lay.findViewById(R.id.context_ed);
        room_context_ed.setHint(R.string.accommodation_room_content_hint);

        select_tv = (TextView) findViewById(R.id.select_tv);
        select_tools = (TextView) findViewById(R.id.select_tools);
        select_tv.setHint(R.string.please_choose);

        if (!"".equals(hostel_info.getHotel_name())) {
            hotel_name_context_ed.setText(hostel_info.getHotel_name());
            room_context_ed.setText(hostel_info.getHotel_room());
            select_tv.setText(hostel_info.getHotel_time());
            address_click.setText(hostel_info.getHotel_address());
        }
        if (ArrangeRouteActivity.maxBean.getCanUpdata().equals("0")) {
            hotel_name_context_ed.setEnabled(false);
            room_context_ed.setEnabled(false);
        } else {
            findViewById(R.id.select_lay).setOnClickListener(this);
        }
    }

    private TextView title;

    private void initTitle() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText(R.string.accommodation_title);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.submit).setOnClickListener(this);
        findViewById(R.id.submit).setVisibility(View.VISIBLE);
        TextView title_right_tv_save = (TextView) findViewById(R.id.submit);
        title_right_tv_save.setVisibility(View.VISIBLE);
        title_right_tv_save.setText(R.string.title_right_tv_save);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                String grogshop_name_context_eds = hotel_name_context_ed.getText().toString().trim();
                String box_context_eds = room_context_ed.getText().toString().trim();
                String address_clicks = address_click.getText().toString().trim();
                String select_tvs = select_tv.getText().toString().trim();

                if ("".equals(grogshop_name_context_eds)) {
                    MyToast("请填写宾馆名称");
                    return;
                }
                if ("".equals(box_context_eds)) {
                    MyToast("请填写房间号");
                    return;
                }
             /*   if ("".equals(address_clicks)) {
                    MyToast("请填写酒店名");
                    return;
                }*/
                if ("".equals(select_tvs)) {
                    MyToast("请填写时间");
                    return;
                }
                if (address_clicks.equals("")) {
                    address_clicks = "杭州";
                }
                hostel_info.setHotel_address(address_clicks);
                hostel_info.setHotel_name(grogshop_name_context_eds);
                hostel_info.setHotel_room(box_context_eds);
                hostel_info.setHotel_time(select_tvs);
                setResult(RESULT_OK);
                finish();

                break;
            case R.id.select_lay:
//                TimePickerView pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
//                    @Override
//                    public void onTimeSelect(Date date, View v) {//选中事件回调
//                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                        String defaultTime = format.format(date);
//                        select_tv.setText(defaultTime);
//                    }
//                })   //.setTitleSize(16)//标题文字大小
//                        // .setTitleText("预算系数")
//                        .setTitleBgColor(Color.WHITE)//标题背景颜色 Night mode
//                        .setTitleColor(getResources().getColor(R.color.text))//标题文字颜色)//标题文字颜色
//                        .setSubmitColor(getResources().getColor(R.color.main_color))//确定按钮文字颜色
//                        .setCancelColor(getResources().getColor(R.color.main_color))//取消按钮文字颜色
//
//                        .setType(TimePickerView.Type.ALL)//默认全部显示
//                        .setOutSideCancelable(false)//点击屏幕，点在控件外部范围时，是否取消显示
//                        .setTitleBgColor(getResources().getColor(R.color.white))//标题背景颜色 Night mode
//                        .setBgColor(getResources().getColor(R.color.white))//滚轮背景颜色 Night mode
//                        .setLabel("年", "月", "日", "时", "分", "秒")
//                        .isDialog(true)//是否显示为对话框样式
//                        .gravity(Gravity.BOTTOM)
//                        .build();
//                pvTime.show();
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                Date curDate = new Date(System.currentTimeMillis());//获取当前时间
                String str = formatter.format(curDate);
                String[] b = str.split("-");
                Calendar startDate = Calendar.getInstance();
                startDate.set(Integer.parseInt(b[0]), Integer.parseInt(b[1]) - 1, Integer.parseInt(b[2]));
                Calendar endDate = Calendar.getInstance();
                endDate.set(2110, 10, 29);
                TimePickerView pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调

                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                        String defaultTime = format.format(date);
                        select_tv.setText(defaultTime);
                    }
                })
                        .setTitleBgColor(Color.WHITE)//标题背景颜色 Night mode
                        .setTitleColor(getResources().getColor(R.color.text))//标题文字颜色)//标题文字颜色
                        .setSubmitColor(getResources().getColor(R.color.main_color))//确定按钮文字颜色
                        .setCancelColor(getResources().getColor(R.color.main_color))//取消按钮文字颜色
                        .setType(TimePickerView.Type.YEAR_MONTH_DAY_HOUR_MIN)//默认全部显示
                        .setOutSideCancelable(false)//点击屏幕，点在控件外部范围时，是否取消显示
                        .setTitleBgColor(getResources().getColor(R.color.white))//标题背景颜色 Night mode
                        .setBgColor(getResources().getColor(R.color.white))//滚轮背景颜色 Night mode
                        .setRangDate(startDate, endDate)//默认是1960-2110年
                        .setDate(startDate)// 默认是系统时间*/
                        .build();
                pvTime.show();
                break;

        }
    }
}
